# -*- coding: utf-8 -*-
import unittest
import sys

sys.path.append('../')

from data import *
from compound import Compound


class BaseObjectTestCase(unittest.TestCase):
	def setUp(self):
		populateDB()

	def tearDown(self):
		clearDB()


class CompoundSimpleTestCase(BaseObjectTestCase):
	def runTest(self):
		c = Compound(1) #the first compound see data for info.
		self.assert_(c != None)

class CompoundBaseTestCase(BaseObjectTestCase):
	def setUp(self):
		BaseObjectTestCase.setUp(self)
		self.c = Compound(1)

class CompoundNameTestCase(CompoundBaseTestCase):
	def runTest(self):
		self.assertEqual(self.c.name, compound1['name'])

class CompoundFormulaTestCase(CompoundBaseTestCase):
	def runTest(self):
		self.assertEqual(self.c.formula, compound1['formula'])

class CompoundIUPACnameTestCase(CompoundBaseTestCase):
	def runTest(self):
		self.assertEqual(self.c.IUPACname, compound1['iupac'])

class CompoundMolTestCase(CompoundBaseTestCase):
	def runTest(self):
		self.assertEqual(self.c.mol.molfile, compound1['molfile'])

class CompoundInchiTestCase(CompoundBaseTestCase):
	def runTest(self):
		self.assertEqual(self.c.inchi.inchi, compound1['inchi'])

class CompoundProductsTestCase(CompoundBaseTestCase):
	def runTest(self):
		self.assertEqual(len(self.c.products), 0)

class CompoundReactantsTestCase(CompoundBaseTestCase):
	def runTest(self):
		self.assertEqual(len(self.c.reactants), 2)
		self.assert_(self.c.reactants[0].name == compound2['name'] or
					 self.c.reactants[1].name == compound2['name'])

class CompoundFingerprintTestCase(CompoundBaseTestCase):
	def runTest(self):
		self.assertEqual(self.c.fingerprint.fpstr, compound1['fp'])

class CompoundUpdateTestCase(CompoundBaseTestCase):
	def setUp(self):
		CompoundBaseTestCase.setUp(self)
		self.c.formula = "H2O"
		self.c.mol.molfile = "this is a diff molfile"
		self.c2 = Compound(2)
		self.c.addProduct(self.c2)

	def runTest(self):
		new_c = Compound(1)
		self.assertEqual(new_c.formula, "H2O")
		self.assertEqual(new_c.mol.molfile, "this is a diff molfile")
		ids = [c.id for c in new_c.products]
		self.assert_(2 in ids)

if __name__=="__main__":
	unittest.main()